<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form :inline="true" :model="listQuery">
        <el-form-item label="关键字">
          <el-input v-model="listQuery.keyword" placeholder="请输入关键字" clearable />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" plain @click="handleSearch">查询</el-button>
          <el-button plain @click="handleReset">重置</el-button>

        </el-form-item>
      </el-form>
    </div>
    <div class="table-container">
      <el-table
        ref="multipleTable"
        :data="list"
        height="100%"
        style="width: 100%"
        @sort-change="sortChange"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column type="index" width="60" label="序号" />
        <el-table-column prop="gmtCreated" label="注册时间" width="140" sortable>
          <template slot-scope="scope">
            <span>{{T.formatDate(scope.row.gmtCreated,'yyyy-MM-dd hh:mm:ss')}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="realName" label="姓名"  width="140" />
        <el-table-column prop="mobile" label="手机号" width="100" />
        <el-table-column prop="nickName" label="昵称" min-width="100" />
        <el-table-column prop="lastLoginTime" label="最后登录时间" width="140" >
          <template slot-scope="scope">
            <span>{{T.formatDate(scope.row.lastLoginTime,'yyyy-MM-dd hh:mm:ss')}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="lastLoginIp" label="最后登录IP" width="100" />

        <el-table-column prop="userRealName" label="姓名" width="100"  />
        <el-table-column prop="userPhone" label="电话" width="120"  />
      </el-table>
      <div class="pagination_handler">
        <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="fetchData" />
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      multipleSelectionRecords: [],
      list: [],
      total: 0,
      listQuery: {
        page: 1,
        limit: 20,
        keyword: '',
        sort: '-gmtCreated'
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => {})
    },
    /* 全选/反选*/
    handleSelectionChange(val) {
      this.multipleSelectionRecords = val
    },
    /* 表格列排序*/
    sortChange(data) {
      const { prop, order } = data
      if (prop) {
        if (order === 'ascending') {
          this.listQuery.sort = '+' + prop
        } else {
          this.listQuery.sort = '-' + prop
        }
      } else {
        this.listQuery.sort = '-gmtCreated'
      }
      this.handleSearch()
    },
    fetchData() {
      this.$store.dispatch('memberUserPage', this.listQuery).then((res) => {
        this.list = res.records
        this.total = res.total
      }).catch((_) => {})
    },
    handleSearch() {
      this.listQuery = {
        ...this.listQuery,
        page: 1
      }
      this.fetchData()
    },
    handleReset() {
      this.listQuery = {
        ...this.listQuery,
        page: 1,
        limit: 20,
        keyword: undefined,
        sort: '-gmtCreated'
      }
      this.fetchData()
    }
  }
}
</script>
  <style lang="scss" scoped>

  </style>

